* Replication do file for the figures included in Brodeur, Cook, Hartley, and Heyes

* Figures and tables referred to by their publication titles

clear

set more off

cd ""

use "merged.dta"

datasignature

assert r(datasignature)=="16390:194(80359):1343769964:425912772"

drop if journal=="Experimental Economics"

drop if experiment==0


* figure_1

capture drop top5
gen top5=0 if zstat!=.
replace top5=1 if journal=="Quarterly Journal of Economics"
replace top5=1 if journal=="Review of Economic Studies"
replace top5=1 if journal=="American Economic Review"
replace top5=1 if journal=="Econometrica"
replace top5=1 if journal=="Journal of Political Economy"

preserve
duplicates drop title, force
bysort year : egen mean_prereg = mean(prereg)
bysort year top5 : egen mean_prereg_top5 = mean(prereg)
 
duplicates drop year top5, force
twoway ///
(connected mean_prereg  year, sort  msymbol(c)   fcolor(gs10) lcolor(gs10)   )  ///
(connected mean_prereg_top5 year if top5==1, sort  msymbol(s)  fcolor(gs10) lcolor(gs10)   )  ///
(connected mean_prereg_top5 year if top5==0, sort  msymbol(t)   fcolor(gs10) lcolor(gs10)   )  ///
, legend(rows(1) label(1 "All") label(2 "Top 5") label(3 "Non-Top 5")) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("", color(black)) xtitle("Publication Year") ytitle("Proportion of Pre-registered Articles") 
graph export "figure_1.pdf", replace
restore

* figure_2

capture drop density1 xaxis1 ci1_1 ci1_2
kdens zstat if zstat<10 , ll(0) ul(10) gen(density1 xaxis1) ci(ci1_1 ci1_2) nograph
twoway ///
(hist zstat if zstat<10,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density1 xaxis1, lcolor(black)) ///
(rarea ci1_1 ci1_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("", color(black)) xtitle("z-Statistic") ytitle("Density")
graph export "figure_2.pdf", replace

* figure_3

local var prereg
levelsof prereg

foreach level in `r(levels)' {
preserve
keep if `var' == `level'
di `level'
local lab : label `var' `level'
capture drop density1 xaxis1 ci1_1 ci1_2
kdens zstat if zstat<10 , ll(0) ul(10) gen(density1 xaxis1) ci(ci1_1 ci1_2) nograph
twoway ///
(hist zstat if zstat<10,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density1 xaxis1, lcolor(black)) ///
(rarea ci1_1 ci1_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("`lab'", color(black)) xtitle("") ytitle("") ///
saving(temp`level'.gph, replace)
restore
}
graph combine temp0.gph temp1.gph, xsize(2) ysize(1) ycommon l1("Density") b1("z-Statistic") graphregion(color(white)) title("", color(black))
graph export "figure_3.pdf", replace

capture erase temp0.gph
capture erase temp1.gph

ksmirnov zstat , by(`var')
local ksresult1: display %5.4f `r(p)'

* figure_4

local var preanalysisplan
levelsof preanalysisplan

foreach level in `r(levels)' {
preserve
keep if `var' == `level' & prereg==1
di `level'
local lab : label `var' `level'
capture drop density1 xaxis1 ci1_1 ci1_2
kdens zstat if zstat<10 , ll(0) ul(10) gen(density1 xaxis1) ci(ci1_1 ci1_2) nograph
twoway ///
(hist zstat if zstat<10,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density1 xaxis1, lcolor(black)) ///
(rarea ci1_1 ci1_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("`lab'", color(black)) xtitle("") ytitle("") ///
saving(temp`level'.gph, replace)
restore
}
graph combine temp0.gph temp1.gph, xsize(2) ysize(1) ycommon l1("Density") b1("z-Statistic") graphregion(color(white)) title("", color(black))
graph export "figure_4.pdf", replace

capture erase temp0.gph
capture erase temp1.gph

* figure_5

use "merged.dta", clear

datasignature

assert r(datasignature)=="16390:194(80359):1343769964:425912772"

gen original_order = _n

merge 1:1 original_order using "completeness.dta", nogen

local figname "figure_hist_interaction"
capture drop nik_binary
gen nik_binary = .
replace nik_binary = 1 if nik_vague_pr=="no" & (nik_primary_var_in_pub_in_pr=="yes" | nik_secondary_var_in_pub_in_pr=="yes")
local label1 "Specific Pre-Registration" "Outcome Pre-Registered"
replace nik_binary = 2 if nik_vague_pr=="no" & (nik_primary_var_in_pub_in_pr!="yes" & nik_secondary_var_in_pub_in_pr!="yes")
local label2 "Specific Pre-Registration" "Outcome Not Pre-Registered"
replace nik_binary = 3 if nik_vague_pr=="yes" & (nik_primary_var_in_pub_in_pr=="yes" | nik_secondary_var_in_pub_in_pr=="yes")
local label3 "Vague Pre-Registration" "Outcome Pre-Registered"
replace nik_binary = 4 if nik_vague_pr=="yes" & (nik_primary_var_in_pub_in_pr!="yes" & nik_secondary_var_in_pub_in_pr!="yes")
local label4 "Vague Pre-Registration" "Outcome Not Pre-Registered"

capture drop density1 xaxis1 ci1_1 ci1_2
kdens zstat if zstat<10 & nik_binary==1, ll(0) ul(10) gen(density1 xaxis1) ci(ci1_1 ci1_2) nograph
twoway ///
(hist zstat if zstat<10 & nik_binary==1,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density1 xaxis1, lcolor(black)) ///
(rarea ci1_1 ci1_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("`label1'", color(black) size(small)) xtitle("") ytitle("") ///
saving(temp1.gph, replace)

capture drop density2 xaxis2 ci2_1 ci2_2
kdens zstat if zstat<10 & nik_binary==2, ll(0) ul(10) gen(density2 xaxis2) ci(ci2_1 ci2_2) nograph
twoway ///
(hist zstat if zstat<10 & nik_binary==2,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density2 xaxis2, lcolor(black)) ///
(rarea ci2_1 ci2_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("`label2'", color(black) size(small)) xtitle("") ytitle("") ///
saving(temp2.gph, replace)

capture drop density3 xaxis3 ci3_1 ci3_2
kdens zstat if zstat<10 & nik_binary==3, ll(0) ul(10) gen(density3 xaxis3) ci(ci3_1 ci3_2) nograph
twoway ///
(hist zstat if zstat<10 & nik_binary==3,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density3 xaxis3, lcolor(black)) ///
(rarea ci3_1 ci3_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("`label3'", color(black) size(small)) xtitle("") ytitle("") ///
saving(temp3.gph, replace)

capture drop density4 xaxis4 ci4_1 ci4_2
kdens zstat if zstat<10 & nik_binary==4, ll(0) ul(10) gen(density4 xaxis4) ci(ci4_1 ci4_2) nograph
twoway ///
(hist zstat if zstat<10 & nik_binary==4,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density4 xaxis4, lcolor(black)) ///
(rarea ci4_1 ci4_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("`label4'", color(black) size(small)) xtitle("") ytitle("") ///
saving(temp4.gph, replace)

graph combine temp1.gph temp2.gph temp3.gph temp4.gph, xsize(4) ysize(4) ycommon l1("Density" ) b1("z-Statistic" ) graphregion(color(white)) title("", color(black)) caption("") rows(2)
graph export "figure_5.pdf", replace

capture erase temp0.gph
capture erase temp1.gph
capture erase temp2.gph
capture erase temp3.gph
capture erase temp4.gph

clear

* figure_6

use "merged.dta"

datasignature

assert r(datasignature)=="16390:194(80359):1343769964:425912772"

drop if journal=="Experimental Economics"

drop if experiment==0

local var pap_power
levelsof pap_power

foreach level in `r(levels)' {
preserve
keep if `var' == `level' & prereg==1
di `level'
local lab : label `var' `level'
capture drop density1 xaxis1 ci1_1 ci1_2
kdens zstat if zstat<10 , ll(0) ul(10) gen(density1 xaxis1) ci(ci1_1 ci1_2) nograph
twoway ///
(hist zstat if zstat<10,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density1 xaxis1, lcolor(black)) ///
(rarea ci1_1 ci1_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("`lab'", color(black)) xtitle("") ytitle("") ///
saving(temp`level'.gph, replace)
restore
}

ksmirnov zstat , by(`var') 
local ksresult1: display %5.4f `r(p)'

graph combine temp0.gph temp1.gph, xsize(2) ysize(1) ycommon l1("Density") b1("z-Statistic") graphregion(color(white)) title("", color(black))
graph export "figure_6.pdf", replace

capture erase temp0.gph
capture erase temp1.gph
capture erase temp2.gph
capture erase temp3.gph
capture erase temp4.gph


* figure_7

capture drop article_has_q_value
gen article_has_q_value = 0
replace article_has_q_value = 1 if strpos(title,"Experimental Evidence from Sierra Leone and The 2014 Ebola Outbreak")>0
replace article_has_q_value = 1 if strpos(title,"Can community service grants foster social and economic integration for youth?")>0
replace article_has_q_value = 1 if strpos(title,"Can vouchers reduce elite capture of local development projects? Experimental evidence from the Solomon Islands")>0
replace article_has_q_value = 1 if strpos(title,"Curating Local Knowledge")>0
replace article_has_q_value = 1 if strpos(title,"Voting and Expenditure Responses to Political Communication")>0
replace article_has_q_value = 1 if strpos(title,"Does inducing informal firms to formalize make sense? Experimental evidence from Benin")>0
replace article_has_q_value = 1 if strpos(title,"Does legal representation increase investment? Evidence from a field experiment in Kenya")>0
replace article_has_q_value = 1 if strpos(title,"Growing Markets through Business Training for Female Entrepreneurs")>0
replace article_has_q_value = 1 if strpos(title,"Household economic strengthening through financial and psychosocial programming: Evidence from a field experiment in South Africa")>0
replace article_has_q_value = 1 if strpos(title,"How information about foreign aid affects public spending decisions: Evidence from a field experiment in Malawi")>0
replace article_has_q_value = 1 if strpos(title,"Making the Grade: The Sensitivity of Education Program Effectiveness to Input Choices and Outcome Measures")>0
replace article_has_q_value = 1 if strpos(title,"On Her Own Account: How Strengthening Women's Financial Control Impacts Labout Supply and Gender Norms")>0
replace article_has_q_value = 1 if strpos(title,"Randomizing Religion: The Impact of Protestant Evangelism on Economic Outcomes")>0
replace article_has_q_value = 1 if strpos(title,"The Effect of Savings Accounts on Interpersonal Financial Relationships: Evidence from a Field Experiment in Rural Kenya")>0
replace article_has_q_value = 1 if strpos(title,"The Effects of Chess Instruction on Academic and Non-cognitive Outcomes: Field Experimental Evidence from a Developing Country")>0
replace article_has_q_value = 1 if strpos(title,"The Impact of Media Censorship: 1984 or Brave New World?")>0
replace article_has_q_value = 1 if strpos(title,"The Persistent Power of Behavioral Change: Long-Run Impacts of Temporary Savings Subsidies for the Poor")>0
replace article_has_q_value = 1 if strpos(title,"The short term impact of a productive asset transfer in families with child labor: Experimental evidence from the Philippines")>0

local var article_has_q_value
levelsof article_has_q_value

label define article_has_q_value 1 "FDR Considered" 0 "FDR Not Considered"
label values article_has_q_value article_has_q_value

foreach level in `r(levels)' {
preserve
keep if `var' == `level'
di `level'
local lab : label `var' `level'
capture drop density1 xaxis1 ci1_1 ci1_2
kdens zstat if zstat<10 , ll(0) ul(10) gen(density1 xaxis1) ci(ci1_1 ci1_2) nograph
twoway ///
(hist zstat if zstat<10,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density1 xaxis1, lcolor(black)) ///
(rarea ci1_1 ci1_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("`lab'", color(black)) xtitle("") ytitle("") ///
saving(temp`level'.gph, replace)
restore
}

ksmirnov zstat , by(`var') 
local ksresult1: display %5.4f `r(p)'

graph combine temp0.gph temp1.gph, xsize(2) ysize(1) ycommon l1("Density") b1("z-Statistic") graphregion(color(white)) title("", color(black))
graph export "figure_7.pdf", replace

capture erase temp0.gph
capture erase temp1.gph
capture erase temp2.gph
capture erase temp3.gph
capture erase temp4.gph


* figure_a1

local var prereg_alt
levelsof prereg_alt

foreach level in `r(levels)' {
preserve
keep if `var' == `level'
di `level'
local lab : label `var' `level'
capture drop density1 xaxis1 ci1_1 ci1_2
kdens zstat if zstat<10 , ll(0) ul(10) gen(density1 xaxis1) ci(ci1_1 ci1_2) nograph
twoway ///
(hist zstat if zstat<10,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density1 xaxis1, lcolor(black)) ///
(rarea ci1_1 ci1_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("`lab'", color(black)) xtitle("") ytitle("") ///
saving(temp`level'.gph, replace)
restore
}
graph combine temp0.gph temp1.gph, xsize(2) ysize(1) ycommon l1("Density") b1("z-Statistic") graphregion(color(white)) title("", color(black))
graph export "figure_a1.pdf", replace

ksmirnov zstat , by(`var') 
local ksresult1: display %5.4f `r(p)'

capture erase temp0.gph
capture erase temp1.gph
capture erase temp2.gph
capture erase temp3.gph
capture erase temp4.gph


* figure_a2
capture drop density1 xaxis1 ci1_1 ci1_2
kdens zstat [fweight = article_weight] if zstat<10 , ll(0) ul(10) gen(density1 xaxis1) ci(ci1_1 ci1_2) nograph
twoway ///
(hist zstat [fweight = article_weight] if zstat<10,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density1 xaxis1, lcolor(black)) ///
(rarea ci1_1 ci1_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("", color(black)) xtitle("z-Statistic") ytitle("Density")
graph export "figure_a2.pdf", replace

* figure_a3
local var prereg
levelsof prereg

foreach level in `r(levels)' {
preserve
keep if `var' == `level'
di `level'
local lab : label `var' `level'
capture drop density1 xaxis1 ci1_1 ci1_2
kdens zstat [fweight = article_weight] if zstat<10 , ll(0) ul(10) gen(density1 xaxis1) ci(ci1_1 ci1_2) nograph
twoway ///
(hist zstat [fweight = article_weight] if zstat<10,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density1 xaxis1, lcolor(black)) ///
(rarea ci1_1 ci1_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("`lab'", color(black)) xtitle("") ytitle("") ///
saving(temp`level'.gph, replace)
restore
}
graph combine temp0.gph temp1.gph, xsize(2) ysize(1) ycommon l1("Density") b1("z-Statistic") graphregion(color(white)) title("", color(black))
graph export "figure_a3.pdf", replace

ksmirnov zstat , by(`var')
local ksresult1: display %5.4f `r(p)'

capture erase temp0.gph
capture erase temp1.gph
capture erase temp2.gph
capture erase temp3.gph
capture erase temp4.gph


* figure_a4
preserve

set seed 123
gen coeff_string_length = length(coeff_string)
gen stderror_string_length = length(stderror_string)
gen random_integer = floor(runiform(0,10))
tostring(random_integer), replace
gen random_integer_2 = floor(runiform(0,10))
tostring(random_integer_2), replace
gen coeff_string_smooth = coeff_string+random_integer
gen stderror_string_smooth = stderror_string+random_integer_2
destring coeff_string_smooth, force replace
destring stderror_string_smooth, force replace

replace zstat = coeff_string_smooth / stderror_string_smooth if coeff_string_length!=0 & coeff_string_smooth!=. & stderror_string_smooth!=. & stderror_string_smooth!=0
replace zstat = abs(zstat)

capture drop density1 xaxis1 ci1_1 ci1_2
kdens zstat   if zstat<10 , ll(0) ul(10) gen(density1 xaxis1) ci(ci1_1 ci1_2) nograph
twoway ///
(hist zstat   if zstat<10,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density1 xaxis1, lcolor(black)) ///
(rarea ci1_1 ci1_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("", color(black)) xtitle("z-Statistic") ytitle("Density")
graph export "figure_a4.pdf", replace

restore

* figure_a5

use "merged.dta", clear

datasignature

assert r(datasignature)=="16390:194(80359):1343769964:425912772"

drop if journal=="Experimental Economics"

drop if experiment==0

set seed 123
gen coeff_string_length = length(coeff_string)
gen stderror_string_length = length(stderror_string)
gen random_integer = floor(runiform(0,10))
tostring(random_integer), replace
gen random_integer_2 = floor(runiform(0,10))
tostring(random_integer_2), replace
gen coeff_string_smooth = coeff_string+random_integer
gen stderror_string_smooth = stderror_string+random_integer_2
destring coeff_string_smooth, force replace
destring stderror_string_smooth, force replace

replace zstat = coeff_string_smooth / stderror_string_smooth if coeff_string_length!=0 & coeff_string_smooth!=. & stderror_string_smooth!=. & stderror_string_smooth!=0
replace zstat = abs(zstat)

local var prereg
levelsof prereg

foreach level in `r(levels)' {
preserve
keep if `var' == `level'
di `level'
local lab : label `var' `level'
capture drop density1 xaxis1 ci1_1 ci1_2
kdens zstat   if zstat<10 , ll(0) ul(10) gen(density1 xaxis1) ci(ci1_1 ci1_2) nograph
twoway ///
(hist zstat   if zstat<10,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density1 xaxis1, lcolor(black)) ///
(rarea ci1_1 ci1_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("`lab'", color(black)) xtitle("") ytitle("") ///
saving(temp`level'.gph, replace)
restore
}
graph combine temp0.gph temp1.gph, xsize(2) ysize(1) ycommon l1("Density") b1("z-Statistic") graphregion(color(white)) title("", color(black))
graph export "figure_a5.pdf", replace


capture erase temp0.gph
capture erase temp1.gph
capture erase temp2.gph
capture erase temp3.gph
capture erase temp4.gph


clear



* figure_a6
* this is a screenshot of g*power, so we dont make it here

* figure_a7

use "merged.dta", clear

datasignature

assert r(datasignature)=="16390:194(80359):1343769964:425912772"

drop if journal=="Experimental Economics"

drop if experiment==0

set seed 123
gen coeff_string_length = length(coeff_string)
gen stderror_string_length = length(stderror_string)
gen random_integer = floor(runiform(0,10))
tostring(random_integer), replace
gen random_integer_2 = floor(runiform(0,10))
tostring(random_integer_2), replace
gen coeff_string_smooth = coeff_string+random_integer
gen stderror_string_smooth = stderror_string+random_integer_2
destring coeff_string_smooth, force replace
destring stderror_string_smooth, force replace

replace zstat = coeff_string_smooth / stderror_string_smooth if coeff_string_length!=0 & coeff_string_smooth!=. & stderror_string_smooth!=. & stderror_string_smooth!=0
replace zstat = abs(zstat)

local var preanalysisplan
levelsof preanalysisplan

foreach level in `r(levels)' {
preserve
keep if `var' == `level' & prereg==1
di `level'
local lab : label `var' `level'
capture drop density1 xaxis1 ci1_1 ci1_2
kdens zstat   if zstat<10 , ll(0) ul(10) gen(density1 xaxis1) ci(ci1_1 ci1_2) nograph
twoway ///
(hist zstat   if zstat<10,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density1 xaxis1, lcolor(black)) ///
(rarea ci1_1 ci1_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("`lab'", color(black)) xtitle("") ytitle("") ///
saving(temp`level'.gph, replace)
restore
}
graph combine temp0.gph temp1.gph, xsize(2) ysize(1) ycommon l1("Density") b1("z-Statistic") graphregion(color(white)) title("", color(black))
graph export "figure_a7.pdf", replace

capture erase temp0.gph
capture erase temp1.gph
capture erase temp2.gph
capture erase temp3.gph
capture erase temp4.gph


* figure_a8

use "merged.dta", clear

datasignature

assert r(datasignature)=="16390:194(80359):1343769964:425912772"

gen original_order = _n

merge 1:1 original_order using "completeness.dta", nogen


capture drop kranz_putz_2022_sign
gen kranz_putz_2022_sign = stderror
label var kranz_putz_2022_sign "KP Significand of S.E."

capture confirm string variable kranz_putz_2022_sign 
if _rc {
	tostring kranz_putz_2022_sign, force replace format(%13.6g)
}

assert length(kranz_putz_2022_sign) - length(subinstr(kranz_putz_2022_sign, ".", "", .)) < 2 

replace kranz_putz_2022_sign = subinstr(kranz_putz_2022_sign,".","",.)
destring kranz_putz_2022_sign, replace
replace kranz_putz_2022_sign = abs(kranz_putz_2022_sign)

capture drop kranz_putz_2022_keep
gen kranz_putz_2022_keep = 0
replace kranz_putz_2022_keep = 1 if kranz_putz_2022_sign >= (1+1.96)/(2*abs(2-1.96)) // keep if significand is above 37 (default), where 37 is from Putz and Kranz (2022 p.3127)

replace kranz_putz_2022_keep = 0 if kranz_putz_2022_sign == 0
capture replace kranz_putz_2022_keep = 1 if report!="s"

label var kranz_putz_2022_keep "=1 to keep KP derounding"

keep if kranz_putz_2022_keep==1

local figname "figure_hist_interaction"
capture drop nik_binary
gen nik_binary = .
replace nik_binary = 1 if nik_vague_pr=="no" & (nik_primary_var_in_pub_in_pr=="yes" | nik_secondary_var_in_pub_in_pr=="yes")
local label1 "Specific Pre-Registration" "Outcome Pre-Registered"
replace nik_binary = 2 if nik_vague_pr=="no" & (nik_primary_var_in_pub_in_pr!="yes" & nik_secondary_var_in_pub_in_pr!="yes")
local label2 "Specific Pre-Registration" "Outcome Not Pre-Registered"
replace nik_binary = 3 if nik_vague_pr=="yes" & (nik_primary_var_in_pub_in_pr=="yes" | nik_secondary_var_in_pub_in_pr=="yes")
local label3 "Vague Pre-Registration" "Outcome Pre-Registered"
replace nik_binary = 4 if nik_vague_pr=="yes" & (nik_primary_var_in_pub_in_pr!="yes" & nik_secondary_var_in_pub_in_pr!="yes")
local label4 "Vague Pre-Registration" "Outcome Not Pre-Registered"

capture drop density1 xaxis1 ci1_1 ci1_2
kdens zstat if zstat<10 & nik_binary==1, ll(0) ul(10) gen(density1 xaxis1) ci(ci1_1 ci1_2) nograph
twoway ///
(hist zstat if zstat<10 & nik_binary==1,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density1 xaxis1, lcolor(black)) ///
(rarea ci1_1 ci1_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("`label1'", color(black) size(small)) xtitle("") ytitle("") ///
saving(temp1.gph, replace)

capture drop density2 xaxis2 ci2_1 ci2_2
kdens zstat if zstat<10 & nik_binary==2, ll(0) ul(10) gen(density2 xaxis2) ci(ci2_1 ci2_2) nograph
twoway ///
(hist zstat if zstat<10 & nik_binary==2,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density2 xaxis2, lcolor(black)) ///
(rarea ci2_1 ci2_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("`label2'", color(black) size(small)) xtitle("") ytitle("") ///
saving(temp2.gph, replace)

capture drop density3 xaxis3 ci3_1 ci3_2
kdens zstat if zstat<10 & nik_binary==3, ll(0) ul(10) gen(density3 xaxis3) ci(ci3_1 ci3_2) nograph
twoway ///
(hist zstat if zstat<10 & nik_binary==3,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density3 xaxis3, lcolor(black)) ///
(rarea ci3_1 ci3_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("`label3'", color(black) size(small)) xtitle("") ytitle("") ///
saving(temp3.gph, replace)

capture drop density4 xaxis4 ci4_1 ci4_2
kdens zstat if zstat<10 & nik_binary==4, ll(0) ul(10) gen(density4 xaxis4) ci(ci4_1 ci4_2) nograph
twoway ///
(hist zstat if zstat<10 & nik_binary==4,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density4 xaxis4, lcolor(black)) ///
(rarea ci4_1 ci4_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("`label4'", color(black) size(small)) xtitle("") ytitle("") ///
saving(temp4.gph, replace)

graph combine temp1.gph temp2.gph temp3.gph temp4.gph, xsize(4) ysize(4) ycommon l1("Density" ) b1("z-Statistic" ) graphregion(color(white)) title("", color(black)) caption("") rows(2)
graph export "figure_a8.pdf", replace


capture erase temp0.gph
capture erase temp1.gph
capture erase temp2.gph
capture erase temp3.gph
capture erase temp4.gph


clear


* figure_a9

use "merged.dta", clear

datasignature

assert r(datasignature)=="16390:194(80359):1343769964:425912772"

drop if journal=="Experimental Economics"

drop if experiment==0

set seed 123
gen coeff_string_length = length(coeff_string)
gen stderror_string_length = length(stderror_string)
gen random_integer = floor(runiform(0,10))
tostring(random_integer), replace
gen random_integer_2 = floor(runiform(0,10))
tostring(random_integer_2), replace
gen coeff_string_smooth = coeff_string+random_integer
gen stderror_string_smooth = stderror_string+random_integer_2
destring coeff_string_smooth, force replace
destring stderror_string_smooth, force replace

replace zstat = coeff_string_smooth / stderror_string_smooth if coeff_string_length!=0 & coeff_string_smooth!=. & stderror_string_smooth!=. & stderror_string_smooth!=0
replace zstat = abs(zstat)

local var pap_power
levelsof pap_power

foreach level in `r(levels)' {
preserve
keep if `var' == `level' & prereg==1
di `level'
local lab : label `var' `level'
capture drop density1 xaxis1 ci1_1 ci1_2
kdens zstat   if zstat<10 , ll(0) ul(10) gen(density1 xaxis1) ci(ci1_1 ci1_2) nograph
twoway ///
(hist zstat   if zstat<10,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density1 xaxis1, lcolor(black)) ///
(rarea ci1_1 ci1_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("`lab'", color(black)) xtitle("") ytitle("") ///
saving(temp`level'.gph, replace)
restore
}
graph combine temp0.gph temp1.gph, xsize(2) ysize(1) ycommon l1("Density") b1("z-Statistic") graphregion(color(white)) title("", color(black))
graph export "figure_a9.pdf", replace

capture erase temp0.gph
capture erase temp1.gph
capture erase temp2.gph
capture erase temp3.gph
capture erase temp4.gph


* figure_a10

use "merged.dta", clear

datasignature

assert r(datasignature)=="16390:194(80359):1343769964:425912772"

drop if journal=="Experimental Economics"

drop if experiment==0

set seed 123
gen coeff_string_length = length(coeff_string)
gen stderror_string_length = length(stderror_string)
gen random_integer = floor(runiform(0,10))
tostring(random_integer), replace
gen random_integer_2 = floor(runiform(0,10))
tostring(random_integer_2), replace
gen coeff_string_smooth = coeff_string+random_integer
gen stderror_string_smooth = stderror_string+random_integer_2
destring coeff_string_smooth, force replace
destring stderror_string_smooth, force replace

replace zstat = coeff_string_smooth / stderror_string_smooth if coeff_string_length!=0 & coeff_string_smooth!=. & stderror_string_smooth!=. & stderror_string_smooth!=0
replace zstat = abs(zstat)

gen article_has_q_value = 0
replace article_has_q_value = 1 if strpos(title,"Experimental Evidence from Sierra Leone and The 2014 Ebola Outbreak")>0
replace article_has_q_value = 1 if strpos(title,"Can community service grants foster social and economic integration for youth?")>0
replace article_has_q_value = 1 if strpos(title,"Can vouchers reduce elite capture of local development projects? Experimental evidence from the Solomon Islands")>0
replace article_has_q_value = 1 if strpos(title,"Curating Local Knowledge")>0
replace article_has_q_value = 1 if strpos(title,"Voting and Expenditure Responses to Political Communication")>0
replace article_has_q_value = 1 if strpos(title,"Does inducing informal firms to formalize make sense? Experimental evidence from Benin")>0
replace article_has_q_value = 1 if strpos(title,"Does legal representation increase investment? Evidence from a field experiment in Kenya")>0
replace article_has_q_value = 1 if strpos(title,"Growing Markets through Business Training for Female Entrepreneurs")>0
replace article_has_q_value = 1 if strpos(title,"Household economic strengthening through financial and psychosocial programming: Evidence from a field experiment in South Africa")>0
replace article_has_q_value = 1 if strpos(title,"How information about foreign aid affects public spending decisions: Evidence from a field experiment in Malawi")>0
replace article_has_q_value = 1 if strpos(title,"Making the Grade: The Sensitivity of Education Program Effectiveness to Input Choices and Outcome Measures")>0
replace article_has_q_value = 1 if strpos(title,"On Her Own Account: How Strengthening Women's Financial Control Impacts Labout Supply and Gender Norms")>0
replace article_has_q_value = 1 if strpos(title,"Randomizing Religion: The Impact of Protestant Evangelism on Economic Outcomes")>0
replace article_has_q_value = 1 if strpos(title,"The Effect of Savings Accounts on Interpersonal Financial Relationships: Evidence from a Field Experiment in Rural Kenya")>0
replace article_has_q_value = 1 if strpos(title,"The Effects of Chess Instruction on Academic and Non-cognitive Outcomes: Field Experimental Evidence from a Developing Country")>0
replace article_has_q_value = 1 if strpos(title,"The Impact of Media Censorship: 1984 or Brave New World?")>0
replace article_has_q_value = 1 if strpos(title,"The Persistent Power of Behavioral Change: Long-Run Impacts of Temporary Savings Subsidies for the Poor")>0
replace article_has_q_value = 1 if strpos(title,"The short term impact of a productive asset transfer in families with child labor: Experimental evidence from the Philippines")>0

local var article_has_q_value
levelsof article_has_q_value

label define article_has_q_value 1 "FDR Considered" 0 "FDR Not Considered"
label values article_has_q_value article_has_q_value

foreach level in `r(levels)' {
preserve
keep if `var' == `level'
di `level'
local lab : label `var' `level'
capture drop density1 xaxis1 ci1_1 ci1_2
kdens zstat if zstat<10 , ll(0) ul(10) gen(density1 xaxis1) ci(ci1_1 ci1_2) nograph
twoway ///
(hist zstat if zstat<10,  fcolor(gs10) lcolor(gs10) width(0.1) barwidth(0.08) ) ///
(line density1 xaxis1, lcolor(black)) ///
(rarea ci1_1 ci1_2 xaxis1 , color(blue%20)) ///
, legend(off) graphregion(color(white)) ylabel(, nogrid) ///
xscale(titlegap(*10)) yscale(titlegap(*10)) ///
title("`lab'", color(black)) xtitle("") ytitle("") ///
saving(temp`level'.gph, replace)
restore
}

ksmirnov zstat , by(`var') 
local ksresult1: display %5.4f `r(p)'

graph combine temp0.gph temp1.gph, xsize(2) ysize(1) ycommon l1("Density") b1("z-Statistic") graphregion(color(white)) title("", color(black))
graph export "figure_a10.pdf", replace

capture erase temp0.gph
capture erase temp1.gph
capture erase temp2.gph
capture erase temp3.gph
capture erase temp4.gph



* figure_a11
* this is commented out just in case you don't want to run it every time
/*
use "merged.dta", clear

datasignature

assert r(datasignature)=="16390:194(80359):1343769964:425912772"

drop if journal=="Experimental Economics"

drop if experiment==0

foreach var of varlist prereg {

levelsof `var'

foreach level in `r(levels)' {

preserve

	keep if `var'==`level'
	
	set obs 26000
	
	local lab : label `var' `level'

sort original_sequence
capture drop x
gen x = _n / 1000
replace x = . if _n > 10000

capture drop observed
kdens zstat if zstat<100, gen(observed) ll(0) at(x) n(10000) nograph
// normalize area under curve to be 1
sum observed 
replace observed = observed / (`r(sum)'/1000)

local updated_df = 1 // initial value - forloop will erase
local updated_np = 0 // initial value - forloop will erase
local updated_difference = 0.9 // initial value

forval df = 1(.1)5 {
forval np = 0(.05)5 {
quietly{
capture drop expected
gen expected = ntden(`df',`np',x)
// normalize area under curve to be 1
sum expected
replace expected = expected / (`r(sum)'/1000)

capture drop difference2
gen difference2 = (observed-expected)^2 if x > 5
sum difference2
local difference2 = `r(sum)'
di "difference squared of " `difference'

if abs(`difference2') < abs(`updated_difference') {
	local updated_difference =  `difference2' // updates to the new one
	local updated_df = `df' // updates to the better one
	local updated_np = `np' // updates to the better one
}	
}
}
}

capture drop expected
gen expected = ntden(`updated_df',`updated_np',x)
// normalize area under curve to be 1
sum expected
replace expected = expected / (`r(sum)'/1000)

di "smallest difference of " `updated_difference' " found at " `updated_df' " deg of freedom and " `updated_np' " non-central parameter"

quietly{
//////
count if zstat >= 0 & zstat < 1.65  & zstat!=.
local obs = r(N)

count if zstat <= 10 & zstat!=.
local all = r(N)

local mass_no_star = `obs' / `all' 
local mass_no_star_exp = nt(`updated_df',`updated_np',1.65)/(nt(`updated_df',`updated_np',10))
local diff_no = `mass_no_star' - `mass_no_star_exp'

//////
count if zstat >= 1.65 & zstat < 1.96  & zstat!=.
local obs = r(N)

count if zstat <= 10 & zstat!=.
local all = r(N)

local mass_one_star = `obs' / `all' 
local mass_one_star_exp = (((nt(`updated_df',`updated_np',1.96)))-((nt(`updated_df',`updated_np',1.65))))/(nt(`updated_df',`updated_np',10))
local diff_one = `mass_one_star' - `mass_one_star_exp'

//////
count if zstat >= 1.96 & zstat < 2.58 & zstat!=.
local obs = r(N)

count if zstat <= 10 & zstat!=.
local all = r(N)

local mass_two_star = `obs' / `all' 
local mass_two_star_exp = (((nt(`updated_df',`updated_np',2.58)))-((nt(`updated_df',`updated_np',1.96))))/(nt(`updated_df',`updated_np',10))
local diff_two = `mass_two_star' - `mass_two_star_exp'

//////
count if zstat >= 2.58 & zstat < 5.00 & zstat!=.
local obs = r(N)

count if zstat <= 10 & zstat!=.
local all = r(N)

local mass_three_star = `obs' / `all' 
local mass_three_star_exp = (((nt(`updated_df',`updated_np',5.00)))-((nt(`updated_df',`updated_np',2.58))))/(nt(`updated_df',`updated_np',10))
local diff_three = `mass_three_star' - `mass_three_star_exp'

//////
count if zstat >= 5 & zstat <= 10.00 & zstat!=.
local obs = r(N)

count if zstat <= 10 & zstat!=.
local all = r(N)

local mass_tail = `obs' / `all' 
local mass_over_5_exp = (((nt(`updated_df',`updated_np',10.00)))-((nt(`updated_df',`updated_np',5.000))))/(nt(`updated_df',`updated_np',10))
local updated_difference = `mass_tail' - `mass_over_5_exp'

local diff_no = round(`diff_no',0.001)
local diff_one = round(`diff_one',0.001)
local diff_two = round(`diff_two',0.001)
local diff_three = round(`diff_three',0.001)
local updated_difference = round(`updated_difference',0.001)
local updated_np = round(`updated_np',0.01)
}

capture drop density1
capture drop xaxis1
capture drop ci1*

kdens zstat if zstat<10 , ll(0) ul(10) gen(density1 xaxis1) ci(ci1_1 ci1_2) nograph
twoway ///
	(line density1 xaxis1, lcolor(black)) ///
	(rarea ci1_1 ci1_2 xaxis1 , color(blue%20)) ///
	(line expected x, lpattern(dash) sort) ///
	, scheme(s1mono) ///
	xlabel(0 1.65 "*" 1.96 "**" 2.58 "***" 5 10) ///
	xmlabel(0.825 "(`diff_no')" 1.805 "(`diff_one')" 2.27 "(`diff_two')" 3.79 "(`diff_three')" 7.5 "(`updated_difference')", noticks  labgap(7) angle(vertical)) ///
	title("`lab'", color(black)) ///
	ytitle("Density") ///
	xtitle("") xline(1.65 1.96 2.58, lwidth(vvthin)) ///
	legend(off pos(2) ring(0) col(1) lab(3 "t~(`updated_df',`updated_np')") lab(1 "Observed") lab(2 "95% CI")) ///
	note("t~(`updated_df',`updated_np')", ring(0) pos(2)) ///
	saving(temp`level'.gph, replace)
	restore
}


graph combine temp0.gph temp1.gph , xsize(2) ysize(1) ycommon l1("Density") b1("z-Statistic") graphregion(color(white)) ///
title("", color(black))
graph export "figure_a11.pdf", replace


}
*/

* figure_a12

use "merged.dta", clear

datasignature

assert r(datasignature)=="16390:194(80359):1343769964:425912772"


foreach var of varlist prereg {

levelsof `var'

foreach level in `r(levels)' {

preserve

keep if `var'==`level'

gen ptop1 = 2*(1 - normal(zstat))

gen ptop2= 2*(1 - normal(zstat)) // (leaving both in to change minimally the R code from Elliot et al.)

drop if ptop1 == .
drop if ptop2 == .
drop if ptop1 > 1

capture drop id
egen id = group(title)

keep ptop1 ptop2 id

export delimited using "figure_a12_input_to_elliot_`var'_`level'.csv", replace

count if ptop1 < 0.15

restore

}
}
